<template>
<div class="planeDialog">
  <zhlDialog
    ref="refcustomfromdialog"
    class="my-dialog"
    :width="width"
    :title="dialogtitle"
  >
    <div id="previewMain">
      <previewpage
        ref="previewPagemain"
        :postData="postData"
        :propsData="propsData"
        @initFrom="initFrom"
      ></previewpage>
    </div>
  </zhlDialog>
  </div>
</template>
<script>
import previewpage from '@/views/index.vue'
import { apiComm } from '@/api/index.js'
export default {
  props: ['dialogclose'],
  data() {
    return {
      js: '',
      css: '',
      html: '',
      propsData: {},
      from: undefined,
      visible: false,
      width: '70%',
      dialogtitle: '查看信息',
      postData: {
        type: 'refreshFrame',
        data: {
          generateConf: {
            fileName: '测试',
            type: 'file'
          },
          html: this.html,
          js: '{}',
          css: this.css,
          scripts: [],
          links: []
        }
      }
    }
  },
  components: { previewpage },
  methods: {
    liulanfrom(fromid, businessid) {
      if (fromid === undefined || fromid === null) {
        this.$message.error('参数错误！！')
        return false
      }
      this.propsData.businessid = businessid
      apiComm('tappFrom.getFromContent', { fid: fromid }).then(res => {
        if (res.code === 0) {
          if (res.data.length === 0) {
            this.$message.error('找不到表单信息，可能表单已删除！')
            return
          }
          this.dialogtitle = res.data[0].fromname
          this.width = res.data[0].dialogwidth
          const fromcontent = JSON.parse(res.data[0].fromcontent)
          this.js = fromcontent.js
          this.css =
            fromcontent.css !== false
              ? fromcontent.css + fromcontent.systemcss
              : fromcontent.systemcss
          this.propsData.IsPower = '1'
          this.html = fromcontent.html
          this.postData.data.css = this.css
          this.postData.data.html = this.html
          this.postData.data.js = this.js.replace('export default', '')
          this.$refs.refcustomfromdialog.visible = true
          this.$nextTick(() => {
            this.$refs.previewPagemain.previewinit(this.postData)
          })
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    initFrom(from) {
      this.from = from
      const fromdata = from.data()
      fromdata.deviceMode = 'dialog'
      fromdata.dialogclose = this.dialogclose
      function data() {
        return fromdata
      }
      this.from.data = data
    },
    opendialog(fromid, businessid) {
      this.liulanfrom(fromid, businessid)
    },
    clasedialog() {
      this.$refs.refcustomfromdialog.visible = false
    }
  },
  created() {}
}
</script>
<style scoped>
#previewMain {
  padding: 10px;
}
。
.planeDialog >>>.ant-modal-body{
  display: flex;
}
</style>
